﻿using System;
using System.Collections.Generic;
using System.Text;
using OgilvyOne.DALFactory;
using OgilvyOne.Model;

namespace OgilvyOne.BLL
{
    /// <summary>
    /// Cms代理类 
    /// </summary>
    public class CmsProxy
    {
        public static string GetHtml(CmsVo vo)
        {
            if (vo.Tid > 0)
            {//模板参数不为空,以模板ID优先获取模板
                
            }
            else if (vo.Aid > 0)
            {//内容
                if (vo.Preview == 1)
                {
                    CmsArticleBll cab = new CmsArticleBll();
                    vo.CmsArticleInfo = cab.GetCmsArticleModel(vo.Aid);
                }
                else
                {
                    vo.CmsArticleInfo = CmsArticleFrontFactory.create().getCmsArticle(vo.Aid);
                }
                if (vo.CmsArticleInfo != null)
                {
                    vo.Cid = vo.CmsArticleInfo.Columnid;
                    vo.Tid = vo.CmsArticleInfo.Templateid;
                }
                else
                {//内容不存在
                    
                }

            }
            else if (vo.Cid > 0)
            {//栏目
                ColumnBll cb = new ColumnBll();
                ColumnModel cm = cb.GetColumn(vo.Cid);
                if (cm != null)
                {
                    vo.Tid = cm.Templateindex;
                }

            }

            //获取模板
            if (vo.Tid > 0)
            {
                ModelManageBLL mmb = new ModelManageBLL();
                vo.TempInfo = mmb.getModel(vo.Tid);
            }

            if (vo.TempInfo == null) return "<font color='red'>无模板页</font>";
            CommonModel model = new ArticleTemplateType(vo);
            
            return model.GetHtml();
        }

        //internal static CommonModel GetModel(int type, CmsVo vo)
        //{
        //    CommonModel model;
        //    switch (type)
        //    {
        //        case 1://首页
        //            model = new HomeModel(vo);
        //            break;
        //        case 2://活动
        //            model = new AboutModel(vo);
        //            break;
        //        case 3://关于
        //            model = new AboutModel(vo);
        //            break;
        //        case 5://赞助商及其他 
        //            model = new HealthModel(vo);
        //            break;
               
        //        default:
        //            model = new HomeModel(vo);
        //            break;
        //    }
        //    return model;
        //}
       
    }
}
